// pages/f_person_info/index.js
Page({

  /**
   * 页面的初始数据
   */
	data: {
		birthday: '',  //生日
    
		sexList: ['男', '女'],
		inputModelHidden: true,
		inputModalTitle: '',
		inputModalType: '',
		inputModalInputType: '',
		inputModalText: '',
    U_Sex:'',
    U_Age:'',
    U_Birth:'',
    U_Email:'',
    U_Headimgurl:'',
    U_Nickname:'',

		contentList: {
			data: [
				{
					"id": 1,
					"icon": "",
					"text": "性别",
					"text2": "请填写",
					"jumpFlag": "/pages/f_my/index",
				},
				{
					"id": 2,
					"icon": "",
					"text": "年龄",
					"text2": "请填写",
					"jumpFlag": "/pages/f_my/index",
				},
				{
					"id": 3,
					"icon": "",
					"text": "生日",
					"text2": "请填写",
					"jumpFlag": "/pages/f_my/index",
				},
				{
					"id": 4,
					"icon": "",
					"text": "邮箱",
					"text2": "请填写",
					"jumpFlag": "/pages/f_my/index",
				},
			]
		}
	},

  /**
   * 生命周期函数--监听页面加载
   */
	onLoad: function (options) {
    var _this = this;
    var _Token;
    try {
      var value = wx.getStorageSync('Token')
      if (value) {
        // Do something with return value
        _Token = value;
      }
    } catch (e) {
      // Do something when catch error
    }
    wx.request({
      url: "https://www.chnode.xyz/api/My.ashx?",
      data: {
        DataType: "UserDetail",
        Token: _Token,
      },
      success: function (res) {
        console.log(res);
        console.log()
        if (res.data.isok == "false"){

        }else {
          _this.setData({
            U_Headimgurl: res.data.data.U_Headimgurl,
            U_Nickname: res.data.data.U_Nickname,
            U_Sex: res.data.data.U_Sex,
            U_Age: res.data.data.U_Age,
            U_Birth: res.data.data.U_Birth,
            U_Email: res.data.data.U_Email,

          })
        }
      }
    })

	},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
	onReady: function () {

	},

  /**
   * 生命周期函数--监听页面显示
   */
	onShow: function () {

	},

  /**
   * 生命周期函数--监听页面隐藏
   */
	onHide: function () {

	},

  /**
   * 生命周期函数--监听页面卸载
   */
	onUnload: function () {

	},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
	onPullDownRefresh: function () {

	},

  /**
   * 页面上拉触底事件的处理函数
   */
	onReachBottom: function () {

	},

  /**
   * 用户点击右上角分享
   */
	onShareAppMessage: function () {

	},



	/**
	 * 设置性别
	 */
	btnEventSettingSex: function (e) {
		var _this = this;
		wx.showActionSheet({
			itemList: _this.data.sexList,
			success: function (res) {
        console.log(_this.data.U_Age=='女'?'0':'1');
				console.log(_this.data.sexList[res.tapIndex])
        _this.setData({
          U_Sex: _this.data.sexList[res.tapIndex],
        })

        var _Token;
        try {
          var value = wx.getStorageSync('Token')
          if (value) {
            // Do something with return value
            _Token = value;
          }
        } catch (e) {
          // Do something when catch error
        }
        ///////
        wx.request({
          url: "https://www.chnode.xyz/api/My.ashx?",
          data: {
            DataType: "UserUpdate",
            Token: _Token,
            U_Age: _this.data.U_Age == '女' ? '0' : '1',
            U_Birth: _this.data.U_Birth,
            U_Email: _this.data.U_Email,
            U_Sex: _this.data.U_Sex,
          },
          success: function (res) {
            console.log(res)
            if (res.data.isok == "false") {

            } else {

            }
          }
        })

        ///////

			},
		})
	},

	/**
	 * 编辑生日
	 */
	bindBirthdayChange: function (e) {
    var _this = this;
		console.log(e.detail.value)
    console.log(_this.data.U_Age == '女' ? '0' : '1')
    console.log(_this.data.U_Birth)
    console.log(_this.data.U_Email)
    console.log(_this.data.U_Sex)
		this.setData({
			birthday: e.detail.value,
      U_Birth: e.detail.value,
		})

    var _Token;
    try {
      var value = wx.getStorageSync('Token')
      if (value) {
        // Do something with return value
        _Token = value;
      }
    } catch (e) {
      // Do something when catch error
    }
    ///////
    wx.request({
      url: "https://www.chnode.xyz/api/My.ashx?",
      data: {
        DataType: "UserUpdate",
        Token: _Token,
        U_Age: _this.data.U_Age,
        U_Birth: _this.data.U_Birth,
        U_Email: _this.data.U_Email,
        U_Sex: _this.data.U_Sex == '女' ? '0' : '1',
      },
      success: function (res) {
        console.log(res)
        if (res.data.isok == "false") {

        } else {

        }
      }
    })

        ///////
	},

	/**
	 * 设置年龄
	 */
	btnEventSettingAge: function (e) {
		var _this = this;
		_this.setData({
			inputModelHidden: false,
			inputModalTitle: '请输入年龄',
			inputModalType: 'Age',
			inputModalInputType: 'number',

		})
	},
	/**
	 * 设置邮箱
	 */
	btnEventSettingEmail: function (e) {
		var _this = this;
		_this.setData({
			inputModelHidden: false,
			inputModalTitle: '请输入邮箱',
			inputModalType: 'Email',
			inputModalInputType: 'text',
      aa:""
		})
	},

	/**
 * 监听InputModalInput输入
 */
	inputModalInput: function (e) {
    console.log(e),
		this.setData({
			inputModalText: e.detail.value
		})
	},

	//InputModal取消按钮
	inputModelCancel: function (e) {
		this.setData({
			inputModelHidden: true
		})
	},
	//InputModal确认按钮  
	inputModelConfirm: function (e) {
    var _this = this;
    console.log(e),

    
  
		_this.setData({
			inputModelHidden: true,
      
		});
		console.log(_this.data.inputModalText)

    if (_this.data.inputModalType == "Email"){
        console.log("email");
        _this.setData({
          U_Email: _this.data.inputModalText
        })
    }else{
        console.log("age");
        _this.setData({
          U_Age: _this.data.inputModalText
        })
    }

    var _Token;
    try {
      var value = wx.getStorageSync('Token')
      if (value) {
        // Do something with return value
        _Token = value;
      }
    } catch (e) {
      // Do something when catch error
    }
    ///////
    wx.request({
      url: "https://www.chnode.xyz/api/My.ashx?",
      data: {
        DataType: "UserUpdate",
        Token: _Token,
        U_Age: _this.data.U_Age,
        U_Birth: _this.data.U_Birth,
        U_Email: _this.data.U_Email,
        U_Sex: _this.data.U_Sex == '女' ? '0' : '1',
      },
      success: function (res) {
        console.log(res)
        if (res.data.isok == "false") {

        } else {

        }
      }
    })

        ///////

	},
})